package com.czl.module_storehouse.mvp.presenter;

import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.module_base.bean.ListBean;
import com.czl.module_base.http.HttpResponse;
import com.czl.module_base.mvp.presenter.BasePresenter;
import com.czl.module_base.mvp.view.IView;
import com.czl.module_base.observer.AbsHandleSubscriber;
import com.czl.module_storehouse.mvp.model.SortModel;

import java.util.List;

/**
 * @author by xubin,
 * @date on 2022/2/15.
 * PS: Not easy to write code, please indicate.
 */
public class SortPresenter extends BasePresenter<SortModel, IView> {
    public static final String TAG_SORT_LIST = "sort_list";
    public static final String TAG_SORT_DELETE = "sort_delete";
    public static final String TAG_SORT_ADD = "sort_add";
    public static final String TAG_SORT_EDIT = "sort_edit";
    public static final String TAG_SORT_CODE = "sort_code";

    /**
     * 获取物品code
     *
     * @param sortPid
     * @param pCode
     */
    public void getSortCode(String sortPid, String pCode) {
        doSubscribe2(mModel.getSortCode(sortPid, pCode), new AbsHandleSubscriber<HttpResponse<SortBean>>() {
            @Override
            public void onSuccess(HttpResponse<SortBean> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_CODE);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void addSortInfo(SortBean sortBean) {
        doSubscribe2(mModel.addSortInfo(sortBean), new AbsHandleSubscriber<HttpResponse<SortBean>>() {
            @Override
            public void onSuccess(HttpResponse<SortBean> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_ADD);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void editSortInfo(SortBean sortBean) {
        doSubscribe2(mModel.editSortInfo(sortBean), new AbsHandleSubscriber<HttpResponse<SortBean>>() {
            @Override
            public void onSuccess(HttpResponse<SortBean> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_EDIT);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void deleteSortInfo(int sortId) {
        doSubscribe2(mModel.deleteSortInfo(sortId), new AbsHandleSubscriber<HttpResponse<Object>>() {
            @Override
            public void onSuccess(HttpResponse<Object> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_DELETE);
                mView.showHttpResponse(httpResponse);
            }
        });
    }

    public void getSortList(boolean refresh, List<Integer> ids, String name) {
        getSortList(refresh, null, ids, null, name);
    }

    public void getSortList(boolean refresh, Boolean pasteCode, List<Integer> ids, Integer priceInfo, String name) {
        resetPageNo(refresh);
        doSubscribe(mModel.getSortList(mPageNo, pasteCode, ids, priceInfo, name), new AbsHandleSubscriber<HttpResponse<ListBean<SortBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<SortBean>> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_LIST);
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getSortList(Boolean pasteCode, List<Integer> ids, Integer priceInfo, String name) {
        resetPageNo(true);
        doSubscribe2(mModel.getSortList(mPageNo, pasteCode, ids, priceInfo, name), new AbsHandleSubscriber<HttpResponse<ListBean<SortBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<SortBean>> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_LIST);
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }

    public void getSortList(String name) {
        resetPageNo(true);
        doSubscribe2(mModel.getSortList(name, mPageNo), new AbsHandleSubscriber<HttpResponse<ListBean<SortBean>>>() {
            @Override
            public void onSuccess(HttpResponse<ListBean<SortBean>> httpResponse) {
                httpResponse.setRequestTag(TAG_SORT_LIST);
                mView.showData(httpResponse.getData());
                nextPageNo();
            }
        });
    }
}
